package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.purchase.RCPurchaseIncomeRequest;
import com.shrct.businessprocess.purchase.RCPurchaseIncomeRequestCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class RCPurchaseIncomeRequestCriteriaImpl extends HQLBasedPagedQueryCriteria<RCPurchaseIncomeRequest> implements RCPurchaseIncomeRequestCriteria {
  private RCProject project;
  
  public RCProject getProject() {
    return this.project;
  }
  
  public RCPurchaseIncomeRequestCriteria setProject(final RCProject project) {
    this.project = project;
    return this;			
    
  }
  
  private RCEnterprise customer;
  
  public RCEnterprise getCustomer() {
    return this.customer;
  }
  
  public RCPurchaseIncomeRequestCriteria setCustomer(final RCEnterprise customer) {
    this.customer = customer;
    return this;			
    
  }
  
  private String invoiceNumber;
  
  public String getInvoiceNumber() {
    return this.invoiceNumber;
  }
  
  public RCPurchaseIncomeRequestCriteria setInvoiceNumber(final String invoiceNumber) {
    this.invoiceNumber = invoiceNumber;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.purchase.impl.RCPurchaseIncomeRequestImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProject()) ){
    	hql += " and ((this.project) = (:project))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCustomer()) ){
    	hql += " and ((this.customerContract.customer) = (:customer))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInvoiceNumber()) ){
    	hql += " and (this.invoiceNumber  LIKE :invoiceNumber)" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.project.code",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProject())){
    	query.setParameter("project",getProject()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCustomer())){
    	query.setParameter("customer",getCustomer()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInvoiceNumber())){
    	query.setParameter("invoiceNumber",getInvoiceNumber()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCPurchaseIncomeRequestCriteriaImpl() {
    initOrderBys();
  }
}
